package com.example.jpushtest;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.gykj.push.JPushActivity;
import com.gykj.push.PushCenter;
import com.gykj.push.PushListener;


public class MainActivity extends JPushActivity implements View.OnClickListener, PushListener {
    private Button mInit;
    private Button mStopPush;
    private Button mResumePush;
    private Button mGetRid;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initView();
        setPushListener(this);//注册监听
    }

    private void initView(){

        mInit = (Button)findViewById(R.id.init);
        mInit.setOnClickListener(this);

        mStopPush = (Button)findViewById(R.id.stopPush);
        mStopPush.setOnClickListener(this);

        mResumePush = (Button)findViewById(R.id.resumePush);
        mResumePush.setOnClickListener(this);

        mGetRid = (Button) findViewById(R.id.getRegistrationId);
        mGetRid.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        Toast.makeText(this, "点击", Toast.LENGTH_SHORT).show();

        switch (v.getId()) {
            case R.id.init:
                PushCenter.initPush(getApplicationContext(),false);
                break;
            case R.id.stopPush:
                PushCenter.stopPush(getApplicationContext());
                break;
            case R.id.resumePush:
                PushCenter.resumePush(getApplicationContext());
                break;
            case R.id.getRegistrationId:
                String rid =  PushCenter.getRegistrationID(getApplicationContext());
                if (!rid.isEmpty()) {
                    Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show();

                } else {
                    Toast.makeText(this, "授权失败", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }





    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onRegisterId(String regId) {
        log("id"+regId);
    }

    @Override
    public void onMessageReceived(String title, String message, String extras, String msgId) {
        log("message"+title+message+extras+msgId);
    }

    @Override
    public void onNotificationReceived(String title, String alert, String extras, int notificationId) {
        log("notificationR"+title+alert+extras+extras);

    }

    @Override
    public void onNotificationOpened(String title, String alert, String extras, int notificationId) {
        log("notificationO"+title+alert+extras+notificationId);

    }

    @Override
    public void onNotificationClicked(String actionExtra) {
        log("notificationC"+actionExtra);

    }

    @Override
    public void onConnectionChanged(boolean connect) {
        log("notificationC"+connect);

    }

    @Override
    public void onUndefinedEvent(String bundle) {
        log("notificationC"+bundle);

    }
    private void log(String msg){
        Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
    }

    //for receive customer msg from jpush server

}
